﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NiceManage.Common;

namespace NiceManage.Controllers
{
    public class LoginController : Controller
    {
        // GET: Login
        public ActionResult Index()
        {
            return View();
        }

        public JsonResult login(string username, string password)
        {
            var bll = new Login();
            //session存储，下次再验证
            if (bll.VerifyPas(username, password))
            {
                HttpContext.Session.SetString("user", username);
                return Json("true");
            }
            return Json("false");
          
        }
        public string register(string username, string password)
        {
            var login = new Login();
            login.Register(username, password);
            return "OK";
        }

        public IActionResult logout()
        {
            //移除存储的session对象
            HttpContext.Session.Remove("user");
            Redirect("login/index");
          return  RedirectToAction(nameof(Index));
        }
        // POST: Login/Create
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                // TODO: Add insert logic here

                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }

        // GET: Login/Edit/5
        public ActionResult Edit(int id)
        {
            return View();
        }

        // POST: Login/Edit/5
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(int id, IFormCollection collection)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }

        // GET: Login/Delete/5
        public ActionResult Delete(int id)
        {
            return View();
        }

   
    }
}